import { Component, OnInit } from '@angular/core';
import { HttpService } from '../../../services/http.service';
import { Router } from '@angular/router';
import { NotarizationInfoService } from '../../../services/notarization-info.service';
import { BaseUiService } from '../../../services/base-ui.service';

@Component({
  selector: 'app-notayconter',
  templateUrl: './notayconter.page.html',
  styleUrls: ['./notayconter.page.scss'],
})
export class NotayconterPage implements OnInit {
  public selectNum:any
  public matterList:any
  public list:any
  public isShowNotary = true;
  public nowNotary = '';
  public notaryList: Array<object>;
  constructor(
    public BaseUiService: BaseUiService,
    public router: Router,
    public HttpService: HttpService,
    public NotarizationInfoService:NotarizationInfoService,
  ) {}

  ngOnInit() {
    this.seach()
  }
  seach(){
    this.HttpService.GET_matterTree({}).then(res=>{
      console.log(res, "11");
      if(res["code"]==200){
        this.matterList = res["items"]
      }
    })
  }

  // chooseNotary(item,index){

  // }

  selectNotary(){
    this.HttpService.GET_notaryOffice({}).then(res=>{
      console.log(res, "11");
      if(res["code"]==200){
        this.notaryList = res["items"];
        this.isShowNotary = false;
      }
    })
  }

  selectClick(id:any){
    this.selectNum = id 
    this.matterList[id].children.forEach(e => {
      e['listSelect'] = false
    })
    this.list = this.matterList[id].children
  }
  select1Click(e:any,name:string){
    
    this.list.forEach(element => {
      if(name==element.name){
        element.listSelect = !e
      }
    });
  }
  //下一步
  goApply(){
    if(this.selectNum == undefined){
      this.BaseUiService.showToast('请选择公证用途','danger','top')
    }else{
      let p =this.list.filter(e =>{
        return e.listSelect == true
      })
      if(p.length==0){
        this.BaseUiService.showToast('请选择公证事项','danger','top')
      }else{
        this.router.navigate(['/transaction/applyinfo'])
        this.NotarizationInfoService.setNotayUse(this.matterList[this.selectNum].name)
        this.NotarizationInfoService.setNotayMatter(p)
      }
    }
  }
  
}
